<template>
  <div class="tree">
    <el-tree
        :props="props"
        :load="loadNode"
        :highlight-current="true"
        lazy
        node-key="orgNo"
        ref="tree"
        show-checkbox
        check-strictly
        @check-change="changetype"
      >
      </el-tree>
  </div>
</template>
<script>
import {gettreefaestapi,gettreechildorgapi} from '@/api/system/menu-manage'
export default {
  name: 'CallPoliceUserTree',
  props: {
    dialogVisible: {
      type:Boolean
    }
  },
  data() {
    return {
      props: {
        label: 'orgName',
        children: 'children',
      }
    };
  },

  mounted() {
    
  },

  methods: {
    changetype(val){
      this.$emit('changetype',this.$refs.tree.getCheckedNodes(false, true))
    },
        // 用户树懒加载
    async loadNode (node, resolve) {
      if (node.level === 0) {
        // 初始的级数（最顶层）
        const { data: { list } } = await gettreefaestapi({ pageNo: 0, pageSize: 1000 })
        return resolve(list)
      }
      if (node.level >= 1) {
        const { data: { list } } = await gettreechildorgapi({ parentOrgNo: node.data.orgNo })
        return resolve(list)
      }
    }
  },
  watch: {
    dialogVisible(val) {
      console.log(val);
      
      if(!val) this.$refs.tree.setCheckedKeys([]);
    }
  }
};
</script>
<style scoped>
.tree{
  height: 500px;
  overflow-y: auto;
}
</style>